package com.xiyuan.smartutils.reflect;

import com.xiyuan.smartutils.Systems;
import com.xiyuan.smartutils.Types;

import java.lang.reflect.ParameterizedType;
import java.lang.reflect.Type;

/**
 *
 * @author xiyuan-lgz 2023-09-18 @version v1.0.0 新建与整理
 */

@SuppressWarnings("unchecked")
public class TypeReference<T> {
    protected final Type type;
    protected final Class<? super T> rawType;
    
    public TypeReference() {
        Type superClass = getClass().getGenericSuperclass();
        type = ((ParameterizedType) superClass).getActualTypeArguments()[0];
        rawType = (Class<? super T>) Types.getRawType(type);
    }
    
    public Class<? extends T> getRawType() {
        return (Class<? extends T>) rawType;
    }
    
    @Override
    public String toString() {
        return rawType.toString();
    }
}
